package cn.westv.scps.service.sms.template.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.westv.scps.dao.BaseDao;
import cn.westv.scps.domain.SmsTemplateEntity;
import cn.westv.scps.domain.SysMessageEntity;
import cn.westv.scps.service.sms.template.ISmsTemplateService;
import cn.westv.scps.utils.Page;

@Service
@Transactional
public class SmsTemplateServiceImpl implements ISmsTemplateService {
	@Resource(name = "baseDao")
	private BaseDao baseDao;

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<SmsTemplateEntity> find(String hql, Class<SmsTemplateEntity> entityClass, Object[] params) {
		return baseDao.find(hql, entityClass, params);
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public SmsTemplateEntity get(Class<SmsTemplateEntity> entityClass, Serializable id) {
		return baseDao.get(entityClass, id);
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Page<SmsTemplateEntity> findPage(String hql, Page<SmsTemplateEntity> page,
			Class<SmsTemplateEntity> entityClass, Object[] params) {
		return baseDao.findPage(hql, page, entityClass, params);
	}

	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void saveOrUpdate(SmsTemplateEntity entity) {
		baseDao.saveOrUpdate(entity);
	}

	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void saveOrUpdateAll(Collection<SmsTemplateEntity> entitys) {
		baseDao.saveOrUpdateAll(entitys);
	}

	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void deleteById(Class<SmsTemplateEntity> entityClass, Serializable id) {
		baseDao.deleteById(entityClass, id);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	public void delete(Class<SmsTemplateEntity> entityClass, Serializable[] ids) {
		baseDao.delete(entityClass, ids);

	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<SmsTemplateEntity> querySQL(String SQL, Object[] params, Class<SmsTemplateEntity> entityClass) {
		return baseDao.querySQL(SQL, params, entityClass);
	}

	@Override
	public SmsTemplateEntity findByCode(String code) {
		List<SmsTemplateEntity> list = baseDao.find("from SmsTemplateEntity where code = ?", SmsTemplateEntity.class,
				new Object[] { code });
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
}
